package com.wc.acwing.思维.Q2070_整数拼接;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.HashMap;
import java.util.Map;
import java.util.StringTokenizer;

/**
 * @Author congge
 * @Date 2024/3/19 12:36
 * @description https://www.acwing.com/problem/content/description/2070/
 */
public class Main {
    static FastReader sc = new FastReader();
    static PrintWriter out = new PrintWriter(System.out);
    static int N = 100010;
    static int[] a = new int[N];
    static int M = 15;
    static int n, k;

    // 思路: Ai * 10 ^ n + Aj == 0 (% k) , Ai * 10 ^ n % k + Aj % k == k || 0
    public static void main(String[] args) {

        // map1[i]<key,value>表示 i位长度的数字 % k 的key,有value个
        Map<Integer, Integer>[] maps1 = new Map[M];

        // map2[i]<key,value> 表示10^i次方的数 % k 的key,有value个
        Map<Integer, Integer>[] maps2 = new Map[M];
        for (int i = 0; i < M; i++) {
            maps1[i] = new HashMap<>();
            maps2[i] = new HashMap<>();
        }

        n = sc.nextInt();
        k = sc.nextInt();
        for (int i = 1; i <= n; i++) a[i] = sc.nextInt();

        for (int i = 1; i <= n; i++) {
            int re = a[i] % k;
            int t = String.valueOf(a[i]).length();
            maps1[t].put(re, maps1[t].getOrDefault(re, 0) + 1);
        }

        for (int i = 1; i <= n; i++) {
            int p = a[i] % k;
            for (int j = 1; j < M; j++) {
                p = p * 10 % k;
                maps2[j].put(p, maps2[j].getOrDefault(p, 0) + 1);
            }
        }

        long res = 0;
        // 是自己拼接成的就--, Ai % k == 0 => Ai * 10 ^ n % k == 0
        for (int i = 1; i <= n; i++) if (a[i] % k == 0) res--;

        for (int i = 1; i < M; i++) {
            Map<Integer, Integer> m1 = maps1[i];
            Map<Integer, Integer> m2 = maps2[i];
            for (int key : m1.keySet()) {
                if (key == 0) {
                    res += (long) m1.get(key) * m2.getOrDefault(key, 0);
                } else {
                    res += (long) m1.get(key) * m2.getOrDefault(k - key, 0);
                }
            }
        }
        out.println(res);
        out.flush();
    }
}

class FastReader {
    StringTokenizer st;
    BufferedReader br;

    FastReader() {
        br = new BufferedReader(new InputStreamReader(System.in));
    }

    String next() {
        while (st == null || !st.hasMoreElements()) {
            try {
                st = new StringTokenizer(br.readLine());
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return st.nextToken();
    }

    int nextInt() {
        return Integer.parseInt(next());
    }

    String nextLine() {
        String s = "";
        try {
            s = br.readLine();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return s;
    }

    long nextLong() {
        return Long.parseLong(next());
    }

    double nextDouble() {
        return Double.parseDouble(next());
    }

    // 是否由下一个
    boolean hasNext() {
        while (st == null || !st.hasMoreTokens()) {
            try {
                String line = br.readLine();
                if (line == null)
                    return false;
                st = new StringTokenizer(line);
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return true;
    }
}